/******************************************
 * Author: Dave Spadea, Spadea Enterprises, Inc.
 * Date: November 2010
 * 
 * This code is released by Spadea Enterprises, Inc for general consumption 
 * under the Apache Software License.
 * 
 */


package net.spadea.framework.messaging;

import javax.jms.Connection;


import org.apache.activemq.ActiveMQConnectionFactory;
import java.util.HashMap;

public class BrokerConnection {

    private static HashMap<String,Connection> connections = new HashMap<String,Connection>();
    
	private static synchronized Connection connect(String url) {
		if ( ! connections.containsKey(url) ) {
			try {

            	   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
                   Connection conn = factory.createConnection();
                   conn.start();
                   connections.put(url, conn);

               } catch(Exception e) {
                       e.printStackTrace();
                       System.exit(1);
               }
		}
		
		return connections.get(url);
	}
	
	public Connection getConnection(String url) {
		return connect(url);
	}
	
}
